package com.elitel.common.pagelist;

import java.util.List;

import com.github.pagehelper.PageInfo;

public class PageList<X> extends PageInfo<X> {

    public PageList(List<X> list) {
        super(list);
    }

    public PageList(List<X> list, int navigatePages) {
        super(list, navigatePages);
    }

    private static final long serialVersionUID = 1L;

    public PageResult<X> toPageResult() {

        PageResult<X> pr = new PageResult<X>();

        int pageIndex = getPageNum() - 1;
        if (pageIndex < 0) {
            pageIndex = 0;
        }
        pr.setPageIndex(pageIndex);
        pr.setPageSize(getPageSize());
        pr.setPageCount(getPages());
        pr.setRecordCount((int) getTotal());
        pr.setRecordFrom(getStartRow());
        pr.setRecordTo(getEndRow());
        pr.setPageList(getList());

        // assertEquals(1, page.getFirstPage());
        // assertEquals(8, page.getLastPage());
        // assertEquals(true, page.isFirstPage());
        // assertEquals(false, page.isLastPage());
        // assertEquals(false, page.isHasPreviousPage());
        // assertEquals(true, page.isHasNextPage());

        pr.setFooterList(null);
        pr.setFileUrl(null);
        pr.setFileName(null);
        return pr;
    }
}
